package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
 @Autowired
private NursingLevelMapper nursingLevelMapper;
    //查询所有护理等级
    @Override
    public List<NursingLevelVo> getlistAll() {

        List<NursingLevelVo> nursingLevel=nursingLevelMapper.getlistAll();
      return nursingLevel;
    }

    //新增
    @Override
    public void createInsert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevel.setCreateTime(LocalDateTime.now());
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevel.setCreateBy(1L);

        nursingLevelMapper.createInsert(nursingLevel);
    }
    //条件分页查询
    @Override
    public PageResponse<NursingLevelVo> getListByPage(Integer pageNum, Integer pageSize, String name, Integer status) {

        //1.设置PageHelper页码和每页显示多少条
        PageHelper.startPage(pageNum,pageSize);

       Page<NursingLevelVo> page= nursingLevelMapper.selectByPage(name,status);


        //3.封装PageResponse返回
        PageResponse<NursingLevelVo> pageResponse = new PageResponse<>(page);

        pageResponse.setRecords(page.getResult());

        return pageResponse;
    }
    //根据id查询
    @Override
    public NursingLevelVo getById(Integer id) {
        NursingLevelVo nursingLevelVo =nursingLevelMapper.getById(id);
        return nursingLevelVo;
    }
    //修改
    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        //1.将nursingLevelDto转换为 nursingLevel
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);

    }

    //删除
    @Override
    public void deleteId(Integer id) {
        nursingLevelMapper.deleteId(id);

    }

    //启用禁用
    @Override
    public void Enable(Integer id, Integer status) {
        nursingLevelMapper.Enable(id,status);
    }
}

